﻿@model WaiGaoQiaoWeb.Models.CardDeleteVM
@{
    ViewBag.Title = "CardDeleteIndex";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    <script type="text/javascript" language="javascript">
        var maiheight = document.documentElement.clientHeight;
        var mainWidth = document.documentElement.clientWidth - 10; // 减去边框和左边的宽度
        $(document).ready(function () {
            var otherpm = $("#title").height() + $("#findDiv").height(); // 290;
            var gh = maiheight - otherpm - 80;
            var option = {
                height: gh,
                width: mainWidth,
                url: '@Url.Action("GetCardDeleteList")', // 参数要放在）括号的外面
                dataType: 'json',
                colModel: [
                    { display: 'PID', name: 'PID', width: 70, sortable: false, hide: true, align: 'left', iskey: true },
                    { display: '人员编号', name: 'EmpNo', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '人员姓名', name: 'PName', width: 100, sortable: false, hide: false, align: 'left' },
					{ display: '部门', name: 'deptName', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '人员类型', name: 'PersonTypeName', width: 200, sortable: false, hide: false, align: 'left' },
                    { display: '卡序列号', name: 'CardSerial', width: 200, sortable: false, hide: false, align: 'left' },
                    { display: '余额', name: 'Balance', width: 100, sortable: false, hide: false, align: 'left' }
				],
                buttons: [
                            { name: 'Delete', displayname: "删除", title: "删除", bclass: 'delete', onpress: toolbarItemDelete_onclick },
							{ separator: true }
						 ],
                title: false,
                singleselected: false,
                usepager: true,
                resizable: true,
                page: 1, //默认当前页  
                total: 1, //总页面数  
                useRp: true, //是否可以动态设置每页显示的结果数  
                rp: 20, // 每页默认的结果数  
                rpOptions: [10, 15, 20], //可选择设定的每页结果数
                showcheckbox: true,
                selectedonclick: true,
                rowbinddata: true,
                query: '',
                hideOnSubmit: true, //隐藏提交  
                autoload: true
            };
            $("#CardDeleteList").flexigrid(option);
            function SelectClick() {
                var vempno = $("#txtEmpNo").val();
                var vpname = $("#txtPName").val();
                var vdeptname = $("#ddldeptName").val();
                var vcardserial = $("#txtCardSerial").val();
                var vgroupid = $("#GroupIdDept").val();
                option.query = vempno + ',' + vpname + ',' + vdeptname + ',' + vcardserial + ',' + vgroupid;
                option.newp = 0;
                $('#CardDeleteList').flexOptions(option).flexReload();
            }
            $("#butfind").click(function (e) {
                SelectClick();
            });
            $("#txtEmpNo").bind('keydown', function (e) {
                var key = e.which;
                if (key == 13) {
                    e.preventDefault();
                    SelectClick();
                }
            });
            $("#txtPName").bind('keydown', function (e) {
                var key = e.which;
                if (key == 13) {
                    e.preventDefault();
                    SelectClick();
                }
            });
            $("#ddldeptName").bind('keydown', function (e) {
                var key = e.which;
                if (key == 13) {
                    e.preventDefault();
                    SelectClick();
                }
            });
            $("#GroupIdDept").bind('keydown', function (e) {
                var key = e.which;
                if (key == 13) {
                    e.preventDefault();
                    SelectClick();
                }
            });
            $("#txtCardSerial").bind('keydown', function (e) {
                var key = e.which;
                if (key == 13) {
                    e.preventDefault();
                    SelectClick();
                }
            });
            $("#ddldeptName").change(function (e) {
                var vdepid = $("#ddldeptName :selected").val();
                $.ajax({
                    type: "POST",
                    url: '@Url.Action("GetGroupDeptChange")',
                    data: { depid: vdepid },
                    dataType: "json",
                    async: true,
                    success: function (data) {
                        $("#GroupIdDept").empty();
                        var t = $("#GroupIdDept")
                        for (var i in data) {
                            var x = data[i];
                            t.append("<option value='" + x.Value + "'>" + x.Text + "</option>");
                        }
                    },
                    error: function () { }
                });
            });
            function toolbarItemDelete_onclick(cmd, grid) {
                var items = $("#CardDeleteList").getSelectedRows();
                if (items.length == 0) {
                    showLoadingMsg("请选择要删除的卡片!", { left: 400, top: 6 }, true, 3000);
                    return false;
                }
                if (!confirm("确定要删除吗？")) {
                    return false;
                }
                var rowcount = 0;
                for (var i = 0; i < items.length; i++) {
                    var PID = items[i][0];
                    $.ajax({
                        type: "POST",
                        url: '@Url.Action("CardDelete")',
                        data: { PID: PID },
                        dataType: "json",
                        async: false,
                        success: function (data) {
                            if (data) {
                                rowcount = rowcount + data;
                            }
                        },
                        error: function () { }
                    });
                }
                refreshGrid();
                showLoadingMsg("共有" + rowcount.toString() + "个卡被删除!", { left: 400, top: 6 }, true, 3000);
            }
            function refreshGrid() {
                $("#CardDeleteList").flexReload();
            }
        });
    </script>
}
<div id="container_sx">
    <div id="mainContent">
        <div id="findDiv">
            <table>
                <tr>
                    <td style="text-align: right;">
                        &nbsp;人员编号：
                    </td>
                    <td style="text-align: left;">
                        @Html.TextBox("txtEmpNo", "", new { @style = "width:170px;" })
                    </td>
                    <td style="text-align: right;">
                        &nbsp;人员姓名：
                    </td>
                    <td style="text-align: left;">
                        @Html.TextBox("txtPName", "", new { @style = "width:170px;" })
                    </td>
                    <td style="text-align: right;">
                        &nbsp;卡序列号：
                    </td>
                    <td style="text-align: left;">
                        @Html.TextBox("txtCardSerial", "", new { @style = "width:170px;" })
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right;">
                        &nbsp;部门：
                    </td>
                    <td style="text-align: left;">
                        @Html.DropDownList("ddldeptName", ViewData["deptName"] as IEnumerable<SelectListItem>,
                                 new { @style = "width:180px; height:22px; font-size:13px;" })
                    </td>
                    <td style="text-align: right;">
                        &nbsp;班组：
                    </td>
                    <td style="text-align: left;">
                       @Html.DropDownListFor(model => model.GroupIdDept,
                                   ViewData["GroupDept"] as IEnumerable<SelectListItem>,
                                   new { @style = "width:180px; height:22px; font-size:13px;" })
                    </td>
                    <td colspan="2">
                        <a id="butfind" class="button" href="javascript:void(0);"><span>查询</span></a>
                    </td>
                </tr>
            </table>
        </div>
        <table id="CardDeleteList" style="display: none;">
        </table>
    </div>
</div>

